package com.xmb.wechat.bean;

import com.chad.library.adapter.base.entity.MultiItemEntity;

import java.util.Calendar;
import java.util.Date;

import io.objectbox.annotation.Entity;
import io.objectbox.annotation.Id;

/**
 * @Author lijiangop
 * @CreateTime 2020/4/22 17:48
 */
@Entity
public class TradeHistoryBean implements MultiItemEntity, Comparable<TradeHistoryBean> {
    @Id
    private long id;
    int     type = 0;
    String  iconUrl;
    int     iconSourceType;
    String  content;
    long    tradeTime;
    boolean isExpend;
    double  money;

    //月份item
    String monthInYear;
    String total;

    public TradeHistoryBean() {
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getIconUrl() {
        return iconUrl;
    }

    public void setIconUrl(String iconUrl) {
        this.iconUrl = iconUrl;
    }

    public int getIconSourceType() {
        return iconSourceType;
    }

    public void setIconSourceType(int iconSourceType) {
        this.iconSourceType = iconSourceType;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public long getTradeTime() {
        return tradeTime;
    }

    public void setTradeTime(long tradeTime) {
        this.tradeTime = tradeTime;
    }

    public boolean isExpend() {
        return isExpend;
    }

    public void setExpend(boolean expend) {
        isExpend = expend;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    public String getMonthInYear() {
        return monthInYear;
    }

    public void setMonthInYear(String monthInYear) {
        this.monthInYear = monthInYear;
    }

    public String getTotal() {
        return total;
    }

    public void setTotal(String total) {
        this.total = total;
    }

    @Override
    public String toString() {
        return "TradeHistoryBean{" +
                "type=" + type +
                ", iconUrl='" + iconUrl + '\'' +
                ", iconSourceType=" + iconSourceType +
                ", content='" + content + '\'' +
                ", tradeTime=" + tradeTime +
                ", isExpend=" + isExpend +
                ", money=" + money +
                ", monthInYear='" + monthInYear + '\'' +
                ", total='" + total + '\'' +
                '}';
    }

    @Override
    public int getItemType() {
        return type;
    }

    @Override
    public int compareTo(TradeHistoryBean argEntity) {
        Calendar thisCalendar = Calendar.getInstance();
        thisCalendar.setTime(new Date(this.getTradeTime()));

        Calendar argCanlendar = Calendar.getInstance();
        argCanlendar.setTime(new Date(argEntity.getTradeTime()));

        if (thisCalendar.get(Calendar.YEAR) > argCanlendar.get(Calendar.YEAR)) {
            return -1;
        } else if (thisCalendar.get(Calendar.YEAR) == argCanlendar.get(Calendar.YEAR)) {//同年
            if (thisCalendar.get(Calendar.MONTH) > argCanlendar.get(Calendar.MONTH)) {
                return -1;
            } else if (thisCalendar.get(Calendar.MONTH) == argCanlendar.get(Calendar.MONTH)) {//同月
                if (thisCalendar.get(Calendar.DAY_OF_MONTH) > argCanlendar.get(Calendar.DAY_OF_MONTH)) {
                    return -1;
                } else if (thisCalendar.get(Calendar.DAY_OF_MONTH) == argCanlendar.get(Calendar.DAY_OF_MONTH)) {//同日
                    long l = thisCalendar.getTimeInMillis() - argCanlendar.getTimeInMillis();
                    return l > 0 ? -1 : 1;
                } else {
                    return 1;
                }
            } else {
                return 1;
            }
        } else {
            return 1;
        }
    }
}
